package com.aigou.admin.service.impl;
import com.aigou.admin.dao.Product_typeDao;
import com.aigou.admin.dao.impl.Product_typeDaoImpl;
import com.aigou.admin.entity.PageEntity;
import com.aigou.admin.entity.Product_type;
import com.aigou.admin.entity.User;
import com.aigou.admin.service.Product_typeService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * @Author: May
 * @Date: 2024/12/3 12:57
 * @Version: 1.0
 */

@Service
@AllArgsConstructor
public class Product_typeServiceImpl implements Product_typeService {

    private Product_typeDao productTypeDao;

    @Override
    public List<Product_type> findAll() {
        return productTypeDao.selectAll();
    }

    @Override
    public Product_type findById(String id) {
        return productTypeDao.selectById(id);
    }

    @Override
    public Boolean save(Product_type productType) {
        return productTypeDao.insert(productType);
    }

    @Override
    public Boolean update(Product_type productType) {
        return productTypeDao.update(productType);
    }

    @Override
    public Boolean remove(String id) {
        return productTypeDao.delete(id);
    }

    @Override
    public PageEntity<Product_type> findUserPage(Integer current, Integer pageSize) {
        //查询用户总数 count(*)
        int total = productTypeDao.selectUserCount();
        //分页查询用户数据 limit
        List<Product_type>  productTypes = productTypeDao.selectUserLimit((current - 1) * pageSize,pageSize);
        //发送数据给前端
        PageEntity<Product_type> pageEntity = new PageEntity<>();
        pageEntity.setCurrent(current);
        pageEntity.setPageSize(pageSize);
        pageEntity.setTotal(total);
        pageEntity.setRecords(productTypes);
        return pageEntity;
    }

    @Override
    public List<Product_type> findByNameContaining(String name) {
        return productTypeDao.findByNameContaining(name);
    }


}
